package math;

public class TTest {
	private double value = 0.0;
	
	public TTest(double[] sample1, double[] sample2, int numSample){
		double sumSample1 = 0.0;
		for(int i=0; i<numSample; i++){
			sumSample1 += sample1[i];
		}
		double avgSample1 = sumSample1 / numSample;
		double sumSqrSample1 = 0.0;
		for(int i=0; i<numSample;i++){
			sumSqrSample1 += (sample1[i]-avgSample1)*(sample1[i]-avgSample1);
		}
		double stdSample1 = sumSqrSample1 / numSample;
		
		double sumSample2 = 0.0;
		for(int i=0; i<numSample; i++){
			sumSample2 += sample2[i];
		}
		double avgSample2 = sumSample2 / numSample;
		double sumSqrSample2 = 0.0;
		for(int i=0; i<numSample;i++){
			sumSqrSample2 += (sample2[i]-avgSample2)*(sample2[i]-avgSample2);
		}
		double stdSample2 = sumSqrSample2 / numSample;
		
		double t = (avgSample1 - avgSample2) / Math.sqrt(stdSample1*stdSample1/numSample + stdSample2*stdSample2/numSample);
		
		this.value = t; 
	}

	public double getValue() {
		return value;
	}
}
